var t = getApp(), e = t.requirejs("core"), FoxUI = t.requirejs("foxui"), n = t.requirejs("jquery");
Page({
    data: {
      id: "",
      type: 0,
      postData: {
        logno: "",
        price: "",
        kpid: "",
      },
      submit: !1,
    },
    onLoad: function(e) {
      var that = this;
      that.setData({
        options: e,
      })
    },
    onShow: function() {
      this.getInfo();
      t.getCache("isIpx") ? this.setData({
          isIpx: !0,
          iphonexnavbar: "fui-iphonex-navbar",
          paddingb: "padding-b"
      }) : this.setData({
          isIpx: !1,
          iphonexnavbar: "",
          paddingb: ""
      });
    },
    getInfo: function() {
      var t = this, options = t.data.options;
      e.get("order/einvoice/getmsg", options, function(res) {
        
        if(res.kpid != 0) {
          var i = { show: !0, type: res.kpmsg.type };
          i.postData = res.kpmsg;
          i.postData.kpid = res.kpid;
        }else{
          var i = { show: !0 };
          i.postData = {
            logno: res.logno,
            price: res.price,
            kpid: res.kpid,
          }
        }
        t.setData(i);
        // console.log(t.data.postData);
      });
    },
    onChange: function(t) {
      var a = t.detail.value, i = e.pdata(t).type, r = this.data.postData;
      r[i] = n.trim(a), this.setData({
        postData: r
      });
    },
    unit: function(p) {
      var type = p.currentTarget.dataset.type
      this.setData({ 
        type: type,
      });
    },
    refundcancel: function(t) {
      var th = this;
      e.confirm("确定您要取消申请?", function() {
        e.post("order/refund/cancel", {
            id: th.data.id
        }, function(e) {
          if(e.error==0) {
            th.getInfo()
          }else {
            wx.showToast({
              title: "失败",
              icon: "none",
              duration: 1500
            })
          }
        }, !0);
      });
    },
    submit: function() {
      var t = this, r = t.data, o = r.options;
      r.postData.id = o.id,
      r.postData.type = r.type;
      var reg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
      if(!t.data.submit) {
        if (!r.postData.header) return void FoxUI.toast(t, "请输入开票抬头");
        if(r.postData.type==0 || r.postData.type==3) {
          if (!r.postData.vatnum) return void FoxUI.toast(t, "请输入增值税号");
        }
        if (!r.postData.mobile) return void FoxUI.toast(t, "请输入手机号码");
        // if (!n.isMobile(r.postData.mobile)) return void FoxUI.toast(t, "请输入正确手机号码");
        // if (!r.postData.email) return void FoxUI.toast(t, "请输入邮箱地址");
        // if (!reg.test(r.postData.email)) return void FoxUI.toast(t, "请输入正确邮箱地址");
        if(r.postData.type==0 || r.postData.type==1) {
          if (!r.postData.regaddress) return void FoxUI.toast(t, "请输入注册地址");
          if (!r.postData.regtel) return void FoxUI.toast(t, "请输入注册电话");
          if (!r.postData.bank) return void FoxUI.toast(t, "请输入开户银行");
          if (!r.postData.banknum) return void FoxUI.toast(t, "请输入开户账号");
        }
        t.setData({ submit: !0 });
        e.post("order/einvoice/submit", r.postData, function(e) {
            t.setData({ submit: !1 });
            0 == e.error ? (FoxUI.toast(t, "提交成功"), setTimeout(function() {
              wx.navigateBack();
            }, 500)) : FoxUI.toast(t, e.message);
        });
      }
    },
});